Hello and welcome to this little shop in this little show.
We will be moving the ball.
This is what the ball looks like at the moment.
We have got the x and y coordinates hard coded with these values.
What we will do to change the position of the ball we are going to create two variables for the x and
y that we'll use to replace these hard coded values.
The variables that we will create for the x and y y coordinates will be used to define the position
at which the ball is drawn at.
All right let's quit the variable.
What I like to do is I want t to start.
Want the want the board game to start from the bottom centre part of the comforts so when I defined
the variable each will reflect starting from the bottom centre part of the compass so to create the
variable type in the one var and then give the x the value of the name on the variable we'll call it
X and will give it a value off of the canvass variable dot
with
Divide by two.
So this will be the value for the X ordinate way replacing this hard coded value here where is variable.
That will create another variable for the Y which is B R and then we give the value
canvas
dot height
minus 30.
So these variables we make the movement of the ball pronounced the more meant you can't tell that the
circle is been painted on the canvas every 10 milliseconds.
By declaring these variables we can see some activity on the ball moving.
Note that every time the ball is painted on the screen is referred to as a frame so each page tin instance
is a frame.
We'll need to add a small value to the X and Y variable so that after every frame is painted on the
canvas or is drawn under cover it will appear that the ball is moving.
So to do this we need to define variable to variables extra variables that will represent these movements.
So let's create the variables here as well.
So we'll define the first one variable D takes and give it a value of.
To.
Next quit variable d y and give it a value of minus 2.
K What we need to do will need to update this drol function so that every time frame in New frame is
painted it updates the X and Y variable.
What that means that on every frame the X and Y variable will be updated with the D X and D Y variable
on every frame.
So what they'll do.
It will make it will make it appear that the ball is painted in a new position on every object.
So let's update this function.
The first time will need to do is change is hard coded value and replace that with.
The eggs variable.
Hand or Y variable.
I'm going to change the radius from 20 to 10 and then the rest will say live the refs the same.
This value here the force option is optional so we can skip that remove that.
I am going to remove that because it is optional.
Finally we need to represent the D X and d d y values so we'll put that just have the bottom before
we close the before this close and curly braces.
So what do we do.
X the value of x plus EPOS to do X and Y loss equates to the Y.
All right saw that on every frame.
The x variable will be updated with this and the Y would be updated with that.
So save this.
All right so let me refresh this so you can see it appears.
Let me refresh that again.
You can see that the movement may refresh consider a moment all right.
What it does it looks appears as if the board is moving bot leaving a trail behind it.
That's why it looks likes on fire.
Run this again and see the ball move in.
It appears it's leaving a tree behind it.
The reason it appears that leaving a trail is because each time frame is painted for the new circle
or new born.
It does not remove the previous one so it has them all together and with continuous trail.
So in the next leg election we can all learn how to clear a compass before each frame.
That way you can see the ball.
They define the moment they collect in the frames and not clearing up after each other is form a continuous
trail.
That's it for this lecture.
Thanks for watching in the next lecture.
We will try and clear each of the frame so that you can see the individual ball at other time on the
compass.
Take care and by phone.